#ifndef FROGSLAYER_H
#define FROGSLAYER_H

#include "Actions.h"


void InitializeDatabase( DBContext& Db )	// Initialize the database
	{
	// Create 3 tables
	// Authorized Vendors
	Db.ExecuteNonQuery ( "CREATE TABLE AuthorizedVendors( VendorName VARCHAR(50), StoreType VARCHAR(50), Address VARCHAR(50), AuthorizedSince DATE)" );
		
	// Card Owners
	Db.ExecuteNonQuery ( "CREATE TABLE CardOwners( OwnerName VARCHAR(50), CardNumber VARCHAR(50), MemberSince DATE, CardBalance FLOAT )" );
		
	// Transactions performed
	Db.ExecuteNonQuery ( "CREATE TABLE TransactionsPerformed( Amount FLOAT, VendorName VARCHAR(50), CardNumber VARCHAR(50), PurchaseType VARCHAR(50), Date DATE, Time TIME, TransactionID VARCHAR(50) )" );
	}

void Run_App( DBContext& Db, vector<string>& AllowedVendors, vector<string>& CardOwners )
	{
	cout << "Welcome to Frogslayer Credit!" << endl << "Which action would you like to perform?" << endl;
	cout << "1 \tInsert a new vendor" << endl;
	cout << "2 \tInsert a new vendor (from file)" << endl;
	cout << "3 \tSee a list of allowed vendors" << endl;
	cout << "4 \tInsert a new card owner" << endl;
	cout << "5 \tInsert a new card owner (from file)" << endl;
	cout << "6 \tSee a list of card owners" << endl;
	cout << "7 \tStore a transaction" << endl;
	cout << "8 \tStore transactions (From a file)" << endl;
	cout << "9 \tGenerate monthly statement of transactions" << endl;
	cout << "10 \tGenerate a transaction summary for a specific vendor" << endl;
	cout << "11 \tQuery transaction table" << endl;
	cout << "12 \tCreate a new table" << endl;
	cout << "13 \tDelete an existing table" << endl;
	cout << "14 \tUpdate tuple (of an existing table)" << endl;
	cout << "15 \tPerform an aggregate query (SUM, COUNT, MIN, MAX)" << endl << endl;
	cout << "0 \tExit" << endl << endl;
	
	cout << "Action: ";
	
	char action;
	int ChosenAction;
	
	ChooseAction:
	while ( true )	
		{
		cin >> action;
		cout << endl;
		// Make sure the user entered a digit
		if ( isdigit( action ) )	// If the user did, read it into the int object
			{
			cin.putback(action);
			cin >> ChosenAction;
			break;
			}
		else	// Otherwise, try again.
			{
			cout << "Please enter a digit" << endl << "Action: ";
			IgnoreLeftOverInput();
			}
		}
		
	// Is the digit with range?
	if ( (ChosenAction < 0) || (ChosenAction > 15) )	// If not, read in a new integer
		{
		cout << "Please enter a digit within [1:15]" << endl << "Action: ";
		goto ChooseAction;
		}
	else	// If so, we are now ready to perform the action
		{
		PerformAction( ChosenAction, Db, AllowedVendors, CardOwners );
		}
	}
	
	
bool Continue()
	{
	IgnoreLeftOverInput();	// Keep previous operations' input from interfering with this one
	char n = ' ';
	cout << "Continue? (Press n to exit ): ";
	cin >> n;
	IgnoreLeftOverInput();
	cout << endl;
	if ( n == 'n' )
		{
		return false;
		}
	return true;
	}
	
#endif

